const { $actions, $formValidator } = require('../../components/index')

Page({
  data: {
    selectorRange: ['美国', '中国', '巴西', '日本'],
    images: [],
  },

  onSubmit(e) {
    console.log('form submit', e.detail)
    const validator = $formValidator()

    validator.validate()
  },

  onActions() {
    $actions().show({
      items: ['Alpha', 'Beta', 'Cigma'],
    })
  },

  onTapStatic() {
    console.log('Tap static control')
    this.setData({
      staticValue: this.data.staticValue ? null : 'Static Value',
    })
  },

  onSwitchChanged(e) {
    console.log('Change switch', e.detail)
  },

  uploadImage(files) {
    console.log('Upload Image:', files)
  },

  onSelectImage(e) {
    const { images } = this.data

    this.setData({ images: images.concat(e.detail.images) })
    console.log('Select Image:', e.detail)
  },

  onUploadError(e) {
    console.log('Uploader Error:', e.detail)
  },

  onRemoveImage(e) {
    const { index } = e.detail
    const { images } = this.data
    images.splice(index, 1)
    this.setData({ images })
  },
})
